import {reqHomeBaseData,reqHomeChartsData} from '@/api'
const actions = {
  async getBaseData({commit}){
    const res = await reqHomeBaseData()
    if(res.code == 200){
      commit('GETBASEDATA',res.data)
      return 'ok'
    }else{
      return Promise.reject('error')
    }
  },
  async getChartsData({commit}){
    const res = await reqHomeChartsData()
    if(res.code == 200){
      commit("GETCHSRTSDATA",res.data)
      return 'ok'
    }else{
      return Promise.reject('error')
    }
  }
}
const mutations = {
  GETBASEDATA(state,data){
    state.baseData = data
  },
  GETCHSRTSDATA(state,data){
    state.chartsData = data
  }

}

const state = {
  baseData:{},
  chartsData:{}
}

const getters = {
  countData(state){
    return state.baseData.countData || []
  },
  tableData(state){
    return state.baseData.tableData || []
  },
  tableLable(state){
    return state.baseData.tableLable || []
  },
  orderData(state){
    return state.chartsData.orderData ||[]
  },
  vedioData(state){
    return state.chartsData.vedioData ||[{}]
  },
  userData(state){
    return state.chartsData.userData ||[{}]
  }
}

export default {
  namespaced:true,
  state,
  actions,
  mutations,
  getters
}